#include <climits>
class Solution {
public:
    long prev = INT_MIN;
    bool isValidBST(TreeNode* root) {
        if (root == nullptr) return true;
        if (!isValidBST(root->left)) return false;
        if (prev < root->val) prev = root->val;
        else return false;
        if (!isValidBST(root->right)) return false;
        return true;
    }
};